package com.ljx.funchat.chat.dao;

import com.ljx.funchat.chat.domain.entity.RoomFriend;
import com.ljx.funchat.chat.domain.enums.RoomStatusEnum;
import com.ljx.funchat.chat.mapper.RoomFriendMapper;
import com.ljx.funchat.chat.service.IRoomFriendService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author LiJunXi
 * @since 2024-02-14
 */
@Service
public class RoomFriendDao extends ServiceImpl<RoomFriendMapper, RoomFriend> {

    public RoomFriend getByRoomId(Long roomId) {
        return lambdaQuery().eq(RoomFriend::getRoomId, roomId).one();
    }

    public List<RoomFriend> listByRoomIds(List<Long> roomIds) {
        return lambdaQuery().in(RoomFriend::getRoomId, roomIds).list();
    }

    public RoomFriend getByKey(String key) {
        return lambdaQuery().eq(RoomFriend::getRoomKey, key).one();
    }

    public void restoreRoom(Long roomId) {
        lambdaUpdate().eq(RoomFriend::getId, roomId)
                .set(RoomFriend::getStatus, RoomStatusEnum.NORMAL.getStatus());
    }

    public void disableRoomFriend(String key) {
        lambdaUpdate().set(RoomFriend::getStatus, RoomStatusEnum.ERROR.getStatus())
                .eq(RoomFriend::getRoomKey, key)
                .update();
    }
}
